import type { ConsultType } from "@/enums";
import type { ConsultOrderPreData, ConsultOrderPreParams, PartialConsult } from "@/types/consult";
import { defineStore } from "pinia";
import { ref } from "vue";

export const useConsultStore = defineStore('cp-consult', ()=>{ 
//定义数据
const consult = ref<PartialConsult>({})


const setType = (type: ConsultType) => {
  consult.value.type = type
}



const setIllnessType = (illnessType: 0 | 1) => {
  consult.value.illnessType = illnessType
}

//收集用户科室的id
const setDepId = (depId: string) => {
  consult.value.depId = depId
}
//收集用户的描述  时间  就诊   图片  
const setIllness = (obj: Pick<PartialConsult,'illnessDesc'|'illnessTime'|'consultFlag'|'pictures'>) => {
  consult.value.illnessDesc = obj.illnessDesc
  consult.value.illnessTime = obj.illnessTime
  consult.value.consultFlag = obj.consultFlag
  consult.value.pictures = obj.pictures
}
  // 收集患者id
  const setPatientId = (patientId: string) => {
    consult.value.patientId = patientId
  }

  // 收集优惠券id
  const setCouponId = (couponId: string) => {
    consult.value.couponId = couponId
  }

  // 支付完成后 清空数据 方便下次重新问诊
  const clear = () => {
    consult.value = {}
  }



return { consult,setType,setIllnessType,setDepId,setIllness,setPatientId,setCouponId,clear }
},
{ persist: true }
)

// 拉取预支付订单信息
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)